package patrol.mobile.com.mobilepatrol.activity.office;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.CommonListActivity;
import patrol.mobile.com.mobilepatrol.adapter.KeShiKeYuanAdapter;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.KeShiKeYuanBean;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;
import patrol.mobile.com.mobilepatrol.widget.MySpinner;

/**
 * Created by K on 2018/9/18.
 * des: 点击科员进来的科室科员
 */
public class KeShiKeYuanActivity extends CommonListActivity {

    private MySpinner mySpinner;
    private String id;
    private List<KeShiKeYuanBean> keShiKeYuanBeans;

    @Override
    public void initView() {
        super.initView();
        /*View itemView = LayoutInflater.from(this).inflate(R.layout.activity_keshi_top, null);
        flContent.addView(itemView);

        mySpinner = itemView.findViewById(R.id.mySpinner);*/
        id = getIntent().getStringExtra("id");
    }

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new KeShiKeYuanAdapter(this);
    }

    @Override
    protected String initTitleName() {
        return "科室考核";
    }

    @Override
    public void configAdapter() {
        super.configAdapter();
        requestData();
    }

    private void requestData() {
        HttpSender sender = new HttpSender(this, baseUrl, Urls.ORG_USER_CHECK_LIST);
        sender.requestPost("id", id, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                JsonParser jp = new JsonParser();
                JsonObject jo = jp.parse(response).getAsJsonObject();

                JsonArray listArray = jo.getAsJsonArray("list");
                keShiKeYuanBeans = GsonUtil.jsonToList(listArray.toString(), KeShiKeYuanBean.class);

                mAdapter.updateItems(keShiKeYuanBeans);
            }
        });
    }

    @Override
    public void setListener() {
        super.setListener();
        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                DeductionActivity.show(KeShiKeYuanActivity.this, 2, keShiKeYuanBeans.get(position).getId());
            }
        });
    }
}
